-module(int).

-include_lib("eunit/include/eunit.hrl").

-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").

setup() ->
    application:start(yamerl).

schema_failsafe_simple_test_() ->
    {setup,
      fun setup/0,
      [
        ?_assertMatch(
          [
            [
              "0", "+0", "-0",
              "123", "+123", "-123",
              "0b101", "+0b101", "-0b101",
              "0o123", "+0o123", "-0o123",
              "0123", "+0123", "-0123",
              "0x1aB", "+0x1aB", "-0x1aB",
              "123:1:23", "+123:1:23", "-123:1:23",
              "1_234", "0b10_10", "0o12_34", "012_34", "0xc3_A9", "1_234:56:8",
              "Not an int", "+Not an int", "-Not an int"
            ]
          ],
          yamerl_constr:file(?FILENAME,
            [{detailed_constr, false}, {schema, failsafe}]) %% No integer parsing
        )
      ]
    }.

schema_failsafe_int_json_simple_test_() ->
    {setup,
      fun setup/0,
      [
        ?_assertMatch(
          [
            [
              0, "+0", 0,
              123, "+123", -123,
              "0b101", "+0b101", "-0b101",
              "0o123", "+0o123", "-0o123",
              "0123", "+0123", "-0123",
              "0x1aB", "+0x1aB", "-0x1aB",
              "123:1:23", "+123:1:23", "-123:1:23",
              "1_234", "0b10_10", "0o12_34", "012_34", "0xc3_A9", "1_234:56:8",
              "Not an int", "+Not an int", "-Not an int"
            ]
          ],
          yamerl_constr:file(?FILENAME,
            [{detailed_constr, false}, {schema, failsafe},
              {node_mods, [yamerl_node_int_json]}])
        )
      ]
    }.

schema_failsafe_int_simple_test_() ->
    {setup,
      fun setup/0,
      [
        ?_assertMatch(
          [
            [
              0, 0, 0,
              123, 123, -123,
              "0b101", "+0b101", "-0b101",
              83, 83, -83,
              123, 123, -123,
              427, 427, -427,
              "123:1:23", "+123:1:23", "-123:1:23",
              "1_234", "0b10_10", "0o12_34", "012_34", "0xc3_A9", "1_234:56:8",
              "Not an int", "+Not an int", "-Not an int"
            ]
          ],
          yamerl_constr:file(?FILENAME,
            [{detailed_constr, false}, {schema, failsafe},
              {node_mods, [yamerl_node_int]}])
        )
      ]
    }.

schema_failsafe_int_ext_simple_test_() ->
    {setup,
      fun setup/0,
      [
        ?_assertMatch(
          [
            [
              0, 0, 0,
              123, 123, -123,
              5, 5, -5,
              "0o123", "+0o123", "-0o123",
              83, 83, -83,
              427, 427, -427,
              442883, 442883, -442883,
              1234, 10, "0o12_34", 668, 50089, 4445768,
              "Not an int", "+Not an int", "-Not an int"
            ]
          ],
          yamerl_constr:file(?FILENAME,
            [{detailed_constr, false}, {schema, failsafe},
              {node_mods, [yamerl_node_int_ext]}])
        )
      ]
    }.

schema_failsafe_detailed_test_() ->
    {setup,
      fun setup/0,
      [
        ?_assertMatch(
          [
            {yamerl_doc,
              {yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
                [{line,1},{column,1}],
                [{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,1},{column,4}],
                    "0"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,2},{column,3}],
                    "+0"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,3},{column,3}],
                    "-0"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,5},{column,4}],
                    "123"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,6},{column,3}],
                    "+123"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,7},{column,3}],
                    "-123"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,9},{column,4}],
                    "0b101"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,10},{column,3}],
                    "+0b101"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,11},{column,3}],
                    "-0b101"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,13},{column,4}],
                    "0o123"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,14},{column,3}],
                    "+0o123"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,15},{column,3}],
                    "-0o123"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,17},{column,4}],
                    "0123"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,18},{column,3}],
                    "+0123"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,19},{column,3}],
                    "-0123"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,21},{column,4}],
                    "0x1aB"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,22},{column,3}],
                    "+0x1aB"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,23},{column,3}],
                    "-0x1aB"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,25},{column,4}],
                    "123:1:23"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,26},{column,3}],
                    "+123:1:23"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,27},{column,3}],
                    "-123:1:23"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,29},{column,3}],
                    "1_234"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,30},{column,3}],
                    "0b10_10"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,31},{column,3}],
                    "0o12_34"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,32},{column,3}],
                    "012_34"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,33},{column,3}],
                    "0xc3_A9"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,34},{column,3}],
                    "1_234:56:8"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,36},{column,4}],
                    "Not an int"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,37},{column,3}],
                    "+Not an int"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,38},{column,3}],
                    "-Not an int"}],
                30}
            }
          ],
          yamerl_constr:file(?FILENAME,
            [{detailed_constr, true}, {schema, failsafe}]) %% No integer parsing
        )
      ]
    }.

schema_failsafe_int_json_detailed_test_() ->
    {setup,
      fun setup/0,
      [
        ?_assertMatch(
          [
            {yamerl_doc,
              {yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
                [{line,1},{column,1}],
                [{yamerl_int,yamerl_node_int_json,
                    "tag:yaml.org,2002:int",
                    [{line,1},{column,4}],
                    0},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,2},{column,3}],
                    "+0"},
                  {yamerl_int,yamerl_node_int_json,
                    "tag:yaml.org,2002:int",
                    [{line,3},{column,3}],
                    0},
                  {yamerl_int,yamerl_node_int_json,
                    "tag:yaml.org,2002:int",
                    [{line,5},{column,4}],
                    123},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,6},{column,3}],
                    "+123"},
                  {yamerl_int,yamerl_node_int_json,
                    "tag:yaml.org,2002:int",
                    [{line,7},{column,3}],
                    -123},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,9},{column,4}],
                    "0b101"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,10},{column,3}],
                    "+0b101"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,11},{column,3}],
                    "-0b101"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,13},{column,4}],
                    "0o123"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,14},{column,3}],
                    "+0o123"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,15},{column,3}],
                    "-0o123"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,17},{column,4}],
                    "0123"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,18},{column,3}],
                    "+0123"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,19},{column,3}],
                    "-0123"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,21},{column,4}],
                    "0x1aB"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,22},{column,3}],
                    "+0x1aB"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,23},{column,3}],
                    "-0x1aB"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,25},{column,4}],
                    "123:1:23"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,26},{column,3}],
                    "+123:1:23"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,27},{column,3}],
                    "-123:1:23"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,29},{column,3}],
                    "1_234"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,30},{column,3}],
                    "0b10_10"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,31},{column,3}],
                    "0o12_34"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,32},{column,3}],
                    "012_34"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,33},{column,3}],
                    "0xc3_A9"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,34},{column,3}],
                    "1_234:56:8"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,36},{column,4}],
                    "Not an int"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,37},{column,3}],
                    "+Not an int"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,38},{column,3}],
                    "-Not an int"}],
                30}
            }
          ],
          yamerl_constr:file(?FILENAME,
            [{detailed_constr, true}, {schema, failsafe},
              {node_mods, [yamerl_node_int_json]}])
        )
      ]
    }.

schema_failsafe_int_detailed_test_() ->
    {setup,
      fun setup/0,
      [
        ?_assertMatch(
          [
            {yamerl_doc,
              {yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
                [{line,1},{column,1}],
                [{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
                    [{line,1},{column,4}],
                    0},
                  {yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
                    [{line,2},{column,3}],
                    0},
                  {yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
                    [{line,3},{column,3}],
                    0},
                  {yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
                    [{line,5},{column,4}],
                    123},
                  {yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
                    [{line,6},{column,3}],
                    123},
                  {yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
                    [{line,7},{column,3}],
                    -123},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,9},{column,4}],
                    "0b101"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,10},{column,3}],
                    "+0b101"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,11},{column,3}],
                    "-0b101"},
                  {yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
                    [{line,13},{column,4}],
                    83},
                  {yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
                    [{line,14},{column,3}],
                    83},
                  {yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
                    [{line,15},{column,3}],
                    -83},
                  {yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
                    [{line,17},{column,4}],
                    123},
                  {yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
                    [{line,18},{column,3}],
                    123},
                  {yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
                    [{line,19},{column,3}],
                    -123},
                  {yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
                    [{line,21},{column,4}],
                    427},
                  {yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
                    [{line,22},{column,3}],
                    427},
                  {yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
                    [{line,23},{column,3}],
                    -427},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,25},{column,4}],
                    "123:1:23"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,26},{column,3}],
                    "+123:1:23"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,27},{column,3}],
                    "-123:1:23"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,29},{column,3}],
                    "1_234"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,30},{column,3}],
                    "0b10_10"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,31},{column,3}],
                    "0o12_34"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,32},{column,3}],
                    "012_34"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,33},{column,3}],
                    "0xc3_A9"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,34},{column,3}],
                    "1_234:56:8"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,36},{column,4}],
                    "Not an int"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,37},{column,3}],
                    "+Not an int"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,38},{column,3}],
                    "-Not an int"}],
                30}
            }
          ],
          yamerl_constr:file(?FILENAME,
            [{detailed_constr, true}, {schema, failsafe},
              {node_mods, [yamerl_node_int]}])
        )
      ]
    }.

schema_failsafe_int_ext_detailed_test_() ->
    {setup,
      fun setup/0,
      [
        ?_assertMatch(
          [
            {yamerl_doc,
              {yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
                [{line,1},{column,1}],
                [{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,1},{column,4}],
                    0},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,2},{column,3}],
                    0},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,3},{column,3}],
                    0},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,5},{column,4}],
                    123},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,6},{column,3}],
                    123},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,7},{column,3}],
                    -123},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,9},{column,4}],
                    5},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,10},{column,3}],
                    5},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,11},{column,3}],
                    -5},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,13},{column,4}],
                    "0o123"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,14},{column,3}],
                    "+0o123"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,15},{column,3}],
                    "-0o123"},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,17},{column,4}],
                    83},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,18},{column,3}],
                    83},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,19},{column,3}],
                    -83},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,21},{column,4}],
                    427},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,22},{column,3}],
                    427},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,23},{column,3}],
                    -427},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,25},{column,4}],
                    442883},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,26},{column,3}],
                    442883},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,27},{column,3}],
                    -442883},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,29},{column,3}],
                    1234},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,30},{column,3}],
                    10},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,31},{column,3}],
                    "0o12_34"},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,32},{column,3}],
                    668},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,33},{column,3}],
                    50089},
                  {yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
                    [{line,34},{column,3}],
                    4445768},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,36},{column,4}],
                    "Not an int"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,37},{column,3}],
                    "+Not an int"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,38},{column,3}],
                    "-Not an int"}],
                30}
            }
          ],
          yamerl_constr:file(?FILENAME,
            [{detailed_constr, true}, {schema, failsafe},
              {node_mods, [yamerl_node_int_ext]}])
        )
      ]
    }.
